# 日历核心算法
import datetime
from typing import Optional
from lunarcalendar import Converter, Solar, Lunar

class CalendarEngine:
    def __init__(self):
        self.current_date = datetime.date.today()

    def get_current_date(self) -> datetime.date:
        return self.current_date

    def switch_month(self, delta: int) -> None:
        """更健壮的月份切换"""
        year = self.current_date.year + (self.current_date.month + delta - 1) // 12
        month = (self.current_date.month + delta - 1) % 12 + 1
        self.current_date = datetime.date(year, month, 1)

    def get_lunar_date(self, solar_date: datetime.date) -> Optional[Lunar]:
        try:
            solar = Solar(solar_date.year, solar_date.month, solar_date.day)
            return Converter.Solar2Lunar(solar)
        except Exception:
            return None
